﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunctionalLayer {

    public class BufferData {
        public DateTime timeDate;
        public double amperage;
        public double distance;
        public int section;
        public double speed;
        public double voltage;
        public double wattage;
        public double temperature;
    }
    /// <summary>
    /// Used to buffer the data that can't be sent 
    /// </summary>
    public class Buffer {
        #region Fields
        private Queue<BufferData> _buffDataQueue;

        private bool _empty;

        public bool Empty
        {
            get { return _empty; }
            set { _empty = value; }
        }
        #endregion

        /// <summary>
        /// Constructor
        /// </summary>
        public Buffer()
        {
            _buffDataQueue = new Queue<BufferData>();
        }

        /// <summary>
        /// Add buffer data to the buffer queue
        /// </summary>
        /// <param name="buffData">buffer data</param>
        public void AddDataBuffer(BufferData buffData)
        {
            _buffDataQueue.Enqueue(buffData);
            _empty = false;
        }

        /// <summary>
        /// Read the first buffer queue buffer data (and delete it afterwards)
        /// </summary>
        /// <returns>first buffer data from the buffer queue</returns>
        public BufferData ReadBuffer()
        {
            if (_buffDataQueue.Count > 1)
            {
                return _buffDataQueue.Dequeue();
            }
            else if (_buffDataQueue.Count == 1)
            {
                _empty = true;
                return _buffDataQueue.Dequeue();
            }
            else
            {
                return null;
            }
        }
    }
}